import { Input, ViewChild, Output, EventEmitter } from "@angular/core";
import { Component, OnInit, ElementRef } from "@angular/core";
import { InitCesiumService } from "./services/InitCesiumService";
import { MapConfig } from "./model/map.model";
declare var Cesium;
@Component({
  selector: "ksp-cesium-map",
  templateUrl: "./cesium-map.component.html",
  styleUrls: ["./cesium-map.component.less"],
})
export class CesiumMapComponent implements OnInit {

  @ViewChild("map") public mapDiv?: ElementRef;
  @Input() options: MapConfig = {}; // 地图div id属性
  /**
   * 地图创建的对象
   */
  @Output() mapCreate = new EventEmitter();
  viewer;
  params;
  lanTianOSGB;
  layer = [
    {
      url: "http://t0.tianditu.com/img_w/wmts?tk=6ac4858482f0852842116eee4ff0574c",
      layer: 'img',
      style: 'default',
      tileMatrixSetID: 'w',
      format: 'tiles',
      maximumLevel: 18
    },
    {
      url: 'http://t0.tianditu.gov.cn/cia_w/wmts?tk=6ac4858482f0852842116eee4ff0574c',
      layer: 'cia',
      style: 'default',
      tileMatrixSetID: 'w',
      format: 'tiles',
      maximumLevel: 18
    },
  ]
  constructor(
    private InitCesiumService: InitCesiumService,
  ) { }

  ngOnInit() { }

  /**
   * 内部初始化地图
   */
  ngAfterViewInit(): void {
    this.viewer = this.InitCesiumService.initViewer(
      this.mapDiv.nativeElement, this.options
    );
    // // 天地地图
    // this.layer.forEach(item => {
    //   var img = new Cesium.WebMapTileServiceImageryProvider({
    //     ...item
    //   });
    //   var layers = this.viewer.scene.imageryLayers;
    //   layers.addImageryProvider(img);
    // })
    this.mapCreate.emit(this.viewer);
  }

}
